<?php
$user = $data['user'];
$honorArr = explode(',', $user['honor']);
//dump($data);


?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>个人荣誉 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
</head>
<body>
<header class="layout-header">
    <div class="container">
        <h1 class="title">个人荣誉</h1>
        <a class="header-back" href="/user/personCenter"><i class="icon icon-left"></i></a>
        <ul class="tool-list">
            <li class="tool-item"><a id="add-honor" href="#">添加</a></li>
        </ul>
    </div>
</header>
<div class="layout-body">
    <div class="container">
        <empty name="user['honor']">
            <div class="content-empty show">
                <div class="picture"></div>
                <div class="no-data">
                    没有添加荣誉<!--，<a href="/competition/listPage">去参加竞赛</a>-->
                </div>
            </div>
            <else />
            <ul id="honor-list" class="list">
                <foreach name="honorArr" item="honor">
                    <li class="list-item">
                        <a class="item-link" href="/stdproduct/listPage">
                            {$honor}<i class="fa fa-close remove-honor" data-honor="{$honor}"></i>
                        </a>
                        <span> </span></li>
                </foreach>
            </ul>

        </empty>
    </div>
</div>
<script>
    var page = {
        isOpen: {$user['is_open']},
        honor: '{$user['honor']}'
    }
</script>
<include file="Common/script" />
<script>
    $('#edit-honor').on('click', function (e) {
        e.preventDefault();
        $('#honor-info-box').hide();
        $('#honor-edit-box').show();
        $(this).hide();
        $('#honor-save').show();
    });

    // 添加荣誉
    $('#add-honor').on('click', function (e) {
        e.preventDefault();

        eui.prompt({
           title: '添加荣誉'
        }, function (value, id) {

            var honor = value;
            if (!honor) {
                eui.msg('请输入内容');
                return;
            }

            if (page.honor) {
                page.honor += ',' + honor;
            } else {
                page.honor = honor;
            }
            $.ajax({
                url: '/user/update',
                data: {
                    honor: page.honor,
                },
                type: 'POST',
                dataType: 'json',
                success: function (obj) {
                    if (obj.code === 0) {
                        eui.msg('添加成功');
                        setTimeout(function () {
                            location.reload(true);
                        }, 800);

                        eui.close(id);

                    } else {
                        eui.msg('添加失败');
                    }

                },
                error: function () {
                    eui.alert('系统出错');
                }
            });
        });

    });

    // 编辑荣誉


    // 保存荣誉
    $('#honor-save').on('click', function (e) {
        e.preventDefault();
        var honorArr = [];
        $('#honor-list').find('input').each(function () {
            var honor = $(this).val();
            if (honor) {
                honorArr.push(honor);
            }
        });

        $.ajax({
            url: '/user/update',
            data: {
                honor: honorArr.join(','),
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    eui.msg('修改成功');
                    setTimeout(function () {
                        location.reload(true);
                    }, 1000);
                } else {
                    eui.msg('修改失败');
                }

            },
            error: function () {
                eui.alert('系统出错');
            }
        })
    });
</script>
</body>
</html>

